from Test import AbstractTest
from MySocket import User, Event
'''
1. Create 3 users
2. Send a broadcast message
3. Broadcast message should be received by all 3 users
'''
class TestBroadcastingMessage(AbstractTest):
    def __init__(self):
    	test_name = "Broadcasting Message"
        super(TestBroadcastingMessage, self).__init__(test_name)

    def run(self):
        # message to be sent
        message = "1|B\n"
        user_1 = User()
        user_2 = User()
        user_3 = User()
        # connect all the users
        user_1.connect()
        user_2.connect()
        user_3.connect()
        # send id
        user_1.mysend("1\n")
        user_2.mysend("2\n")
        user_3.mysend("3\n")
        # create event
        event = Event()
        event.connect()
        event.mysend(message)
        # validation
        if(user_1.myreceive(len(message)) != message):
            return False;
        if(user_2.myreceive(len(message)) != message):
            return False;
        if(user_3.myreceive(len(message)) != message):
            return False;
        return True